Inside Macintosh: Memory

Previous | Chapter Top | Chapter Contents | Next

The System Global Variables

Just as the Toolbox stores information about your drawing environment in a set of QuickDraw global variables within your application partition, the Operating System and Toolbox store information about the entire multiple-application environment in a set of system global variables, also called low-memory global variables. The system global variables are stored in the lowest part of the physical RAM, in the system partition.

Most system global variables are intended for use by system software only, and you should never need to read or write them directly. Current versions of system software contain functions that return values equivalent to most of the important system global variables. Use those routines whenever they are available. However, you might occasionally need to access the value of a system global variable to maintain compatibility with previous versions of system software, or you might need to access a system global variable whose value no equivalent function returns.

The MPW interface file SysEqu.p defines the memory locations at which system global variables are stored in the latest version of system software. For example, SysEqu.p contains lines like these:

CONST
    RndSeed             = $156;     {random number seed (long)}
    Ticks               = $16A;     {ticks since last boot (unsigned long)}
    DeskHook            = $A6C;     {hook for painting desktop (pointer)}
    MBarHeight          = $BAA;     {height of menu bar (integer)}

You can use these memory locations to examine the value of one of these variables. See "Reading and Writing System Global Variables" for instructions on reading and writing the values of system global variables from a high-level language.

You should avoid relying on the value of a system global variable whenever possible. The meanings of many global variables have changed in the past and will change again in the future. Using the system global variables documented in Inside Macintosh is fairly safe, but you risk incompatibility with future versions of system software if you attempt to access global variables defined in the interface files but not explicitly documented.

Even when Inside Macintosh does document a particular system global variable, you should use any available routines to access that variable's value instead of examining it directly. For example, you should use the TickCount function to find the number of ticks since startup instead of examining the Ticks global variable directly.

You should read or write the value of a system global variable only when that variable is documented in Inside Macintosh and when there is no alternate method of reading or writing the information you need.


© 1997 Apple Computer, Inc.

Previous | Chapter Top | Chapter Contents | Next